<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆页面</title>
    <script src="js/vue.js"></script>
    <script src="js/axios-0.18.0.js"></script>
</head>
<body>
    <div id="app">
        <input type="text" placeholder="请输入用户名" v-model="user.username"><br>
        <input type="password" placeholder="请输入密码" v-model="user.password"><br>
        <button @click="login">登陆</button>
    </div>

<script>
    /* 点击登陆按钮,发送数据到后台(post请求,数据是json格式) */
    new Vue({
        el:"#app",
        data:{
            user:{
                username:'',
                password:''
            }
        },
        methods:{
            login(){
                //点击了登陆按钮,发送ajax请求提交登陆信息
                axios.post("/user/login",this.user)
                    .then((resp)=>{
                        if(resp.data.code == '200'){
                            //登陆成功
                            location.href = "/pages/list.html"
                        }else{
                            alert(resp.data.errMsg)
                        }
                    })
            }
        }
    })
</script>

</body>
</html>